package operations;

import games.SimpleMatch;
import home.SimpleMatchHome;

import java.util.List;

import teams.Team;

public class ObtainSimpleMatchHistory implements Runnable {

    private Team team1;

    private Team team2;

    public ObtainSimpleMatchHistory(final Team team1, final Team team2) {
        this.team1 = team1;
        this.team2 = team2;
    }

    @Override
    public void run() {

        List<SimpleMatch> partidos = new SimpleMatchHome().getMatches(this.team1, this.team2);
        int ganadosTeam1 = 0;
        int ganadosTeam2 = 0;
        int empates = 0;

        for (SimpleMatch unPartido : partidos) {
            Team ganador = unPartido.getWinner();

            if (ganador == this.team1) {
                ganadosTeam1++;
            } else {
                if (ganador == this.team2) {
                    ganadosTeam2++;
                } else {
                    empates++;
                }

            }
        }
        System.out.println("Historial de partidos entre: " + this.team1 + " y " + this.team2);
        System.out.println("Partidos ganados por " + this.team1 + ": " + ganadosTeam1);
        System.out.println("Partidos ganados por " + this.team2 + ": " + ganadosTeam2);
        System.out.println("Partidos empatados: " + empates);
    }
}
